package 回溯;

import com.alibaba.fastjson.JSON;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Stream;

/**
 * todo
 *
 * @author songZiHao
 * @version 1.0.0
 * @ClassName 回溯.TestVO.java
 * @createTime 2024年11月20日 16:32:00
 */
@Getter
@Setter
@Accessors(chain = true)
public class TestVO implements Serializable {
    private static final long serialVersionUID = 453207380000413882L;

    private List<UploadItemInfo> itemList;

    private List<UploadPlatformInfo> platformList;

    @Data
    public static class UploadPlatformInfo implements Serializable {

        private static final long serialVersionUID = 6400753589991781013L;

        /**
         * 平台
         */
        private String platform;

        /**
         * 店铺id
         */
        private Long shopId;

        /**
         * 店铺名称
         */
        private String shopName;

    }

    @Data
    public static class UploadItemInfo implements Serializable {

        private static final long serialVersionUID = -1035256020510934330L;

        /**
         * 系统id
         */
        private Long sysItemId;

        /**
         * 商品名称
         */
        private String title;

        /**
         * 是否组合商品
         */
        private Integer isSuit;

        /**
         * sku信息
         */
        private List<UploadSkuInfo> skuList;
    }

    @Data
    @Accessors(chain = true)
    public static class UploadSkuInfo implements Serializable {

        private static final long serialVersionUID = -1035256020510934330L;

        /**
         * 系统skuId
         */
        private Long sysSkuId;

        /**
         * sku名称
         */
        private String title;

    }

    public static void main(String[] args) {
        listFileNames("/Users/songzihao/Downloads/success");
    }


    public static void listFileNames(String directoryPath) {
        Path dir = Paths.get(directoryPath);

        // 检查路径是否存在且确实是一个目录
        if (!Files.exists(dir)) {
            System.out.println("目录不存在: " + directoryPath);
            return;
        }

        if (!Files.isDirectory(dir)) {
            System.out.println("指定的路径不是一个目录: " + directoryPath);
            return;
        }

        StringBuilder sb = new StringBuilder();
        sb.append("update dmj_sku_44 set pic_path= CONCAT(\"https://erp-storage-img.oss-cn-hangzhou.aliyuncs.com/item_archive/\",outer_id,\".png\") where company_id = 325494 and outer_id in ( ' ");
        try (Stream<Path> stream = Files.list(dir)) {
            // 过滤出文件（可选：如果需要包括子目录，可以移除此条件）
            stream.filter(Files::isRegularFile)
                    .forEach(path -> {
                        Path fileName = path.getFileName();
                        String[] split = fileName.toString().split("\\.");
                        sb.append(split[0] + "','");
                        System.out.println(split[0]);
                    });
            System.out.println(Files.list(dir).count());;
            sb.append(" ')");
            System.out.println(sb.toString());
        } catch (IOException e) {
            System.err.println("读取目录时出错: " + directoryPath);
            e.printStackTrace();
        }
    }

}